/*************************************************************************
	> File Name: P1143.cpp
	> Author: yufangze
	> Mail: 2224590123@qq.com
	> Created Time: 2025-02-10 10:41:53
 ************************************************************************/
#include <iostream>
#include <unordered_map>
using namespace std;

int to_ten(string &num, int base) {
    int ans = 0;
    for (int i = num.size() - 1, p = 1; i >= 0; i--, p *= base) {
        if (num[i] >= '0' && num[i] <= '9') {
            ans += (num[i] - '0') * p;
        } else {
            ans += (num[i] - 'A' + 10) * p;
        }
    }
    return ans;
}

unordered_map<int, string> umap = {
    {0, "0"}, {1, "1"}, {2, "2"}, {3, "3"}, {4, "4"}, {5, "5"}, {6, "6"},
    {7, "7"}, {8, "8"}, {9, "9"}, {10, "A"}, {11, "B"}, {12, "C"},
    {13, "D"}, {14, "E"}, {15, "F"}
};

string to_base(int val, int base) {
    string ans = "";
    while (val) {
        int ind = val % base;
        ans.insert(0, umap[ind]);
        val /= base;
    }
    return ans;
}

int main() {
    int base, n;
    string num;
    cin >> n >> num >> base;
    int val = to_ten(num, n);
    string ans = to_base(val, base);
    cout << ans << endl;
    return 0;
}
